//
//  DeviceInfoView.m
//  GoldOperationClient
//
//  Created by yaxue wang on 16/9/22.
//  Copyright © 2016年 展鸿科技. All rights reserved.
//

#import "DeviceInfoView.h"
#import "DeviceInfoCell.h"

@interface DeviceInfoView()
{
    NSArray *_ar;
    NSDictionary *_dict;
}
@property(nonatomic,strong)NSString*type;
@property(nonatomic,strong)NSString*machineUuid;

@end
@implementation DeviceInfoView

-(instancetype)initWithFrame:(CGRect)frame withWarningUuid:(NSString *)machineUuid 
{
    self = [super initWithFrame:frame];
    if (self) {
        self.backgroundColor =[UIColor clearColor];
        self.separatorStyle=UITableViewCellSeparatorStyleNone;
        self.showsVerticalScrollIndicator =NO;
        [self registerClass:[DeviceInfoCell class]forCellReuseIdentifier:@"cell"];
         _ar=[[NSArray alloc]initWithObjects:@"设备名称",@"设备类型",@"设备编号",@"入库时间",@"所属机构", nil];
        _dict=[[NSMutableDictionary alloc]init];

        self.machineUuid=machineUuid;
        [self setTableActionType:CTableActionType_Both];
        [self loadData];
        
    }
    
    return self;
    
}
- (void)loadData{
    [CClass HttpRequestTask:YES withUrl:@"equip_equipInfo"withData:@{@"uuid":self.machineUuid} notifyError:YES onSuccess:^(BaseModel *model) {
        
        _dict =model.B_data;
        [self reloadData];
    } onError:^(BaseModel *model) {
        
    }];
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return 5;
}

- (UITableViewCell*)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    
    DeviceInfoCell *cell = [tableView dequeueReusableCellWithIdentifier:@"cell"];
    if (cell == nil) {
        cell = [[DeviceInfoCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"cell"];
    }

    cell.nameLab.text=[_ar objectAtIndex:indexPath.row];
    if (indexPath.row==0) {
        cell.contexLab.text=[_dict objectForKey:@"name"];
    }else if(indexPath.row==1){
        cell.contexLab.text=[_dict objectForKey:@"type_cd"];

    }else if(indexPath.row==2){
        cell.contexLab.text=[_dict objectForKey:@"code"];

    }else if(indexPath.row==3){
        NSString  *a = [_dict objectForKey:@"created"];
        NSString *timeString = [a substringWithRange:NSMakeRange(0, 16)];
       cell.contexLab.text=timeString;

    }else if(indexPath.row==4){
        cell.contexLab.text=[_dict objectForKey:@"inst"];

    }

  
    return cell;
    
}
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{

    return 45;
}

@end
